import cv2

from paddleocr import PaddleOCR

# 使用默认模型路径
paddleocr = PaddleOCR(lang='ch', show_log=False)
img = cv2.imread('images/o1.jpg')  # 打开需要识别的图片
result = paddleocr.ocr(img)
# """
#         OCR with PaddleOCR

#         Args:
#             img: Image for OCR. It can be an ndarray, img_path, or a list of ndarrays.
#             det: Use text detection or not. If False, only text recognition will be executed. Default is True.
#             rec: Use text recognition or not. If False, only text detection will be executed. Default is True.
#             cls: Use angle classifier or not. Default is True. If True, the text with a rotation of 180 degrees can be recognized. If no text is rotated by 180 degrees, use cls=False to get better performance.
#             bin: Binarize image to black and white. Default is False.
#             inv: Invert image colors. Default is False.
#             alpha_color: Set RGB color Tuple for transparent parts replacement. Default is pure white.
#             slice: Use sliding window inference for large images. Both det and rec must be True. Requires int values for slice["horizontal_stride"], slice["vertical_stride"], slice["merge_x_thres"], slice["merge_y_thres"] (See doc/doc_en/slice_en.md). Default is {}.

#         Returns:
#             If both det and rec are True, returns a list of OCR results for each image. Each OCR result is a list of bounding boxes and recognized text for each detected text region.
#             If det is True and rec is False, returns a list of detected bounding boxes for each image.
#             If det is False and rec is True, returns a list of recognized text for each image.
#             If both det and rec are False, returns a list of angle classification results for each image.

#         Raises:
#             AssertionError: If the input image is not of type ndarray, list, str, or bytes.
#             SystemExit: If det is True and the input is a list of images.

#         Note:
#             - If the angle classifier is not initialized (use_angle_cls=False), it will not be used during the forward process.
#             - For PDF files, if the input is a list of images and the page_num is specified, only the first page_num images will be processed.
#             - The preprocess_image function is used to preprocess the input image by applying alpha color replacement, inversion, and binarization if specified.
#         """
for i in range(len(result[0])):
    logging.info(result[0][i][1][0])   # 输出识别结果
